//
//  BaseViewController.m
//  PiPiPineapple
//
//  Created by 李晓东 on 17/10/27.
//  Copyright © 2017年 PeanutXu. All rights reserved.
//

#import "BaseViewController.h"
#import "TipsViewController.h"

static NSArray *array;

@interface BaseViewController ()
//@property (nonatomic, strong) NSArray *array;
@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        array = [BaseViewController tipsContent];
    });
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

+ (NSArray *)tipsContent{
    // 读取 explain.txt 中的说明.封装成 NSarray
    NSString *path = [[NSBundle mainBundle]pathForResource:@"explain" ofType:@"txt"];
    NSString *tempStr = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
    NSArray *tempArray = [tempStr componentsSeparatedByString:@"\n"];

    tempArray = [tempArray subarrayWithRange:NSMakeRange(0, tempArray.count - 1)];
    return tempArray;
    
}

- (void)explain:(id)sender {
    // 获取点击"说明"按钮的 sender 的 tag
    UIBarButtonItem *barButtonItem = (UIBarButtonItem *)sender;
    NSInteger senderTag = barButtonItem.tag;

    NSMutableString *tips = [NSMutableString stringWithString:array[senderTag]];
    
    if (senderTag == 31) {
        for (int i = 0; i < 17; i++) {
            [tips appendString:array[senderTag + i]];
        }
        
    }
    // 在通过 tag 属性来确定是那个说明
    

    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStyleDone target:nil action:nil];
    [self.navigationController pushViewController:[[TipsViewController alloc]initWithTipsContent:tips] animated:YES];
}

@end
